using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RequestCookiesPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        ViewCookies();
        GetCookies();
        ViewValues();
        ViewCookieByGet();
    }
    void ViewValues()
    {
        Literal1.Text  ="Value of Cookie<br>";
        HttpCookie cookie = Request.Cookies["recentSelection1"];
        string value;
        if (cookie != null)
        {
            value = Convert.ToString(cookie.Value);
            Literal1.Text +=value;
            Literal1.Text +="<br>" ;

        }
        cookie = Request.Cookies["recentSelection2"];
        if (cookie != null)
        {
            value = Convert.ToString(cookie.Value);
            Literal1.Text += value;
            Literal1.Text += "<br>";
        }

        cookie = Request.Cookies["recentSelection3"];
        if (cookie != null)
        {
            value = Convert.ToString(cookie.Value);
            Literal1.Text += value;
            Literal1.Text += "<br>";
        }
    }
    void ViewCookies()
    {
        Literal2.Text="Cookies Collection<br>";
        foreach (string cookie in Request.Cookies)
        {
             Literal2.Text += cookie;            
             Literal2.Text +=": " ;
             Literal2.Text += Request.Cookies[cookie].Value;
             Literal2.Text +="<br>" ;
              
        }
    }
    void ViewCookieByGet()
    {
        Literal4.Text = "Get Value of Cookies "+
        " Collection by get method<br>";
        foreach (string cookie in Request.Cookies)
        {
            Literal4.Text += cookie;
            Literal4.Text += ": ";
            Literal4.Text += Request.Cookies.Get(cookie).Value;
            Literal4.Text += "<br>";

        }
    }
    void GetCookies()
    {
        Literal3.Text = "Cookies Collection<br>";
        for (int i=0; i< Request.Cookies.Count;i++)
        {
            Literal3.Text += Request.Cookies[i].Name;
            Literal3.Text += ": ";
            Literal3.Text += Request.Cookies[i].Value;
            Literal3.Text += "<br>";
        }
    }
}
